#include "stdafx.h"
#include "wf_infoinside.h"
#include "pf_information.h"
#include "pf_snapper.h"



WF_InfoInside::WF_InfoInside(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Info Inside",
                    container, graphicView) {

    contour = new PF_Container(NULL, false);

    for (PF_Entity* e=container.firstEntity(); e!=NULL;
            e=container.nextEntity()) {
        if (e->isSelected()) {
            contour->addEntity(e);
        }
    }
}


WF_InfoInside::~WF_InfoInside() {
    delete contour;
}


QAction* WF_InfoInside::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
/*      QAction* action = new QAction(tr("Point inside contour"),
                                  tr("&Point inside contour"),
                                  QKeySequence(), NULL); */
    QAction* action = new QAction(tr("Point inside contour"), NULL);
    //action->zetStatusTip(tr("Checks if a given point is inside the selected contour"));

    return action;
}

void WF_InfoInside::trigger() {
    bool onContour = false;
    if (PF_Information::isPointInsideContour(pt, contour, &onContour)) {
        PF_DIALOGFACTORY->commandMessage(tr("Point is inside selected contour."));
    } else {
        PF_DIALOGFACTORY->commandMessage(tr("Point is outside selected contour."));
    }
    finish();
}



void WF_InfoInside::mouseMoveEvent(PF_MouseEvent* e) {
    //PF_Vector mouse = snapPoint(e);
    //bool onContour = false;
    /*if (PF_Information::isPointInsideContour(mouse, contour, &onContour)) {
    } else {
    }*/
}



void WF_InfoInside::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    } else {
        pt = snapPoint(e);
        trigger();
    }
}



void WF_InfoInside::updateMouseButtonHints() {
    switch (getStatus()) {
    case 0:
        PF_DIALOGFACTORY->updateMouseWidget(tr("Specify point"),
                                            tr("Cancel"));
        break;
    default:
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        break;
    }
}



void WF_InfoInside::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::CadCursor);
}



void WF_InfoInside::updateToolBar() {
    if (!isFinished()) {
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarSnap);
    } else {
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarInfo);
    }
}

// EOF
